var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var httpPort = 8080;
let channelId = 1;
app.get('/', function (req, res) {
  // res.sendFile(__dirname + '/index.html');
  res.send('启动成功：' + httpPort);
});
//建立链接
io.on('connection', function (socket) {
  console.log('a user connected', new Date());
  //监听聊天信息
  socket.on('chatmessage', (msg) => {
    console.log('this is a ', msg)
    //发送聊天信息
    socket.broadcast.emit('sendmsg', msg);
    // io.emit('send msg', msg)
  })

  socket.on('disconnect', () => {
    console.log('user disconnect');
  })
});

http.listen(httpPort, function () {
  console.log('listening on *:8080');
});
